#include "stdafx.h"
#include "wf_modifydeletequick.h"

#include "wf_selectsingle.h"
#include "pf_snapper.h"
#include "pf_point.h"



WF_ModifyDeleteQuick::WF_ModifyDeleteQuick(
    PF_Container& container,
    PF_GraphicView& graphicView)
        :PF_ActionInterface("Quick Delete Entities",
                    container, graphicView) {

    en = NULL;
}


QAction* WF_ModifyDeleteQuick::createGUIAction(LX_Define::ActionType /*type*/, QObject* parent) {
	// (tr("Delete selected"
	QAction* action = new QAction(tr("&Delete selected"), parent);
	action->setIcon(QIcon(":/extui/modifydelete.png"));
	//action->zetStatusTip(tr("Delete selected entities"));
	action->setShortcut(QKeySequence::Delete);
	return action;
}


/**
 * Deletes all entities that were selected.
 */
void WF_ModifyDeleteQuick::trigger() {

    PF_DEBUG->print("PF_ActionModifyDeleteQuick::trigger()");

    if (en!=NULL) {
        PF_DEBUG->print("Entity found");
        PF_Container* parent = en->getParent();
        if (parent!=NULL) {
            en->setSelected(false);
            graphicView->deleteEntity(en);
            en->changeUndoState();

            if (document) {
                document->startUndoCycle();
                document->addUndoable(en);
                document->endUndoCycle();
            }
        }

    	PF_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
    } else {
        PF_DEBUG->print("PF_ActionModifyDeleteQuick::mousePressEvent:"
                        " Entity is NULL\n");
    }
}



void WF_ModifyDeleteQuick::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::RightButton) {
        init(getStatus()-1);
    } else {
        en = catchEntity(e);
        trigger();
    }
}



void WF_ModifyDeleteQuick::updateMouseButtonHints() {
    switch (getStatus()) {
    case 0:
        PF_DIALOGFACTORY->updateMouseWidget(tr("Pick entity to delete"),
                                       tr("Cancel"));
        break;
    default:
        PF_DIALOGFACTORY->updateMouseWidget("", "");
        break;
    }
}



void WF_ModifyDeleteQuick::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::DelCursor);
}

// EOF
